package com.rain.shoppingscienceproj.ui.utile;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.rain.shoppingscienceproj.R;


/**
 * Author: Rain
 * Create: 2017/12/14 15:34
 */

public class DialogUtils {

    private static Dialog dialog;
    private static TextView tv_data, tv_cancle, tv_sure, tv_send;
    private static EditText et_mesage, et_content;

    public static void dialog(Activity activity, String text) {
        dialog = new Dialog(activity, R.style.MyDialog);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_layout, null);
        tv_data = (TextView) view.findViewById(R.id.tv_data);
        tv_cancle = (TextView) view.findViewById(R.id.tv_cancle);
        tv_sure = (TextView) view.findViewById(R.id.tv_sure);
//        tv_sure.setVisibility(View.GONE);
//        tv_cancle.setBackgroundResource(R.drawable.textview_dialog_back_below);
        tv_data.setText(text);
        tv_cancle.setOnClickListener(v -> dialog.dismiss());
        WindowManager wm = activity.getWindowManager();
        int mWeight = wm.getDefaultDisplay().getWidth();
        dialog.setContentView(view, new ViewGroup.LayoutParams((int) (mWeight * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT));
        dialog.show();
    }

    public static void dialogRegis(Activity activity, String text) {
        dialog = new Dialog(activity, R.style.MyDialog);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_layout, null);
        tv_data = (TextView) view.findViewById(R.id.tv_data);
        tv_cancle = (TextView) view.findViewById(R.id.tv_cancle);
        tv_sure = (TextView) view.findViewById(R.id.tv_sure);
        View view_bottom = view.findViewById(R.id.view_bottom);
        View view_text = view.findViewById(R.id.view_text);
        view_bottom.setVisibility(View.GONE);
        view_text.setVisibility(View.GONE);
        tv_cancle.setText("");
        tv_sure.setText("确定");
        tv_data.setText(text);
        WindowManager wm = activity.getWindowManager();
        int mWeight = wm.getDefaultDisplay().getWidth();
        dialog.setContentView(view, new ViewGroup.LayoutParams((int) (mWeight * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT));
        dialog.show();
    }

    public static void dialogRegis(Activity activity) {
        dialog = new Dialog(activity, R.style.MyDialog);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_edit, null);
        et_content = view.findViewById(R.id.tv_data);
        tv_cancle = (TextView) view.findViewById(R.id.tv_cancle);
        tv_sure = (TextView) view.findViewById(R.id.tv_sure);
        View view_bottom = view.findViewById(R.id.view_bottom);
        View view_text = view.findViewById(R.id.view_text);
        view_bottom.setVisibility(View.GONE);
        view_text.setVisibility(View.GONE);
        tv_cancle.setText("取消");
        tv_sure.setText("确定");
        tv_cancle.setOnClickListener(v -> dialog.dismiss());
        WindowManager wm = activity.getWindowManager();
        int mWeight = wm.getDefaultDisplay().getWidth();
        dialog.setContentView(view, new ViewGroup.LayoutParams((int) (mWeight * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT));
        dialog.show();
    }
//    public static void dialog(Activity activity) {
//        dialog = new Dialog(activity, R.style.MyDialog);
//        dialog.setCancelable(false);
//        dialog.setCanceledOnTouchOutside(true);
//        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_cancel_order_layout, null);
//        tv_sure = view.findViewById(R.id.tv_sure);
//        et_mesage = view.findViewById(R.id.et_message);
//        WindowManager wm = activity.getWindowManager();
//        int mWeight = wm.getDefaultDisplay().getWidth();
//        int mHeight = wm.getDefaultDisplay().getHeight();
//        dialog.setContentView(view, new ViewGroup.LayoutParams((int) (mWeight * 0.95), (mHeight / 3)));
//        dialog.show();
//    }

    public static void commDialog(Activity activity, String texthint) {
        dialog = new Dialog(activity, R.style.BottomDialog);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Content前设定
        View view = LayoutInflater.from(activity).inflate(R.layout.layout_article_detaile_comm, null);
        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(true);
        // 设置宽度为屏宽, 靠近屏幕底部。
        Window window = dialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.BOTTOM; // 紧贴底部
        lp.alpha = 1;
        lp.dimAmount = 0.5f;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 宽度持平
        window.setAttributes(lp);
        window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        et_content = view.findViewById(R.id.et_content);
        tv_send = view.findViewById(R.id.tv_send);
        et_content.setHint(texthint);
        et_content.setFocusable(true);
        et_content.setFocusableInTouchMode(true);
        et_content.requestFocus();
        dialog.show();
    }

    public static void dismissDialog() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    public static TextView getTv_send() {
        return tv_send;
    }

    public static void setTv_send(TextView tv_send) {
        DialogUtils.tv_send = tv_send;
    }

    public static EditText getEt_content() {
        return et_content;
    }

    public static void setEt_content(EditText et_content) {
        DialogUtils.et_content = et_content;
    }

    public static EditText getEt_mesage() {
        return et_mesage;
    }

    public static void setEt_mesage(EditText et_mesage) {
        DialogUtils.et_mesage = et_mesage;
    }

    public static TextView getTv_data() {
        return tv_data;
    }

    public static TextView getTv_cancle() {
        return tv_cancle;
    }

    public static TextView getTv_sure() {
        return tv_sure;
    }
}
